var prize={
		normal:0,
		third:0,
		second:0,
		first:0,
		grand:0,
		i:0
}
$("div.prize button").attr("disabled",false);
var a1,b1,a2,b2,a3,b3,a4,b4,a5;
$("#normal").click(function(){
	$(this).addClass("start");
	$(this).siblings().removeClass("start");
		$("div.prize-number").html("");
		$("#grand").css("background-image","url(img/grandprizeOff.png)");
		$("#normal").css("background-image","url(img/normalprizeOn.png)");
		$("#third").css("background-image","url(img/thirdprizeOff.png)");
		$("#second").css("background-image","url(img/secondprizeOff.png)");
		$("#first").css("background-image","url(img/firstprizeOff.png)");
		//var i=0,
		//a1=setTimeout(function(){
		//	start();	
		//	i++
	//	})
	//	b1=setInterval(function(){
	//		if(i<=49){
	//			start()
	//		}
	//		i++;
	//	},8500)

	
});
$("#third").click(function(){
	$(this).addClass("start");
	$(this).siblings().removeClass("start");
		$("div.prize-number").html("");
		$("#grand").css("background-image","url(img/grandprizeOff.png)");
		$("#normal").css("background-image","url(img/normalprizeOff.png)");
		$("#third").css("background-image","url(img/thirdprizeOn.png)");
		$("#second").css("background-image","url(img/secondprizeOff.png)");
		$("#first").css("background-image","url(img/firstprizeOff.png)");
		//prize.third=1;
		//var i=0;
		//a2=setTimeout(function(){
		//	start();	
		//	i++;
		//})
		//b2=setInterval(function(){
		//	if(i<=24){
		//		start()
		//	}
		//	i++;
		//},8500)
});
$("#second").click(function(){
	$(this).addClass("start");
	$(this).siblings().removeClass("start");
		$("div.prize-number").html("");
		$("#grand").css("background-image","url(img/grandprizeOff.png)");
		$("#normal").css("background-image","url(img/normalprizeOff.png)");
		$("#third").css("background-image","url(img/thirdprizeOff.png)");
		$("#second").css("background-image","url(img/secondprizeOn.png)");
		$("#first").css("background-image","url(img/firstprizeOff.png)");
		//prize.second=1;
		//var i=0;
		//a3=setTimeout(function(){
		//	start();	
		//	i++;
		//})
		//b3=setInterval(function(){
		//	if(i<=9){	
		//		start()
		//	}
		//	i++;
		//},8500)
});
$("#first").click(function(){
	$(this).addClass("start");
	$(this).siblings().removeClass("start");
		$("div.prize-number").html("");
		$("#grand").css("background-image","url(img/grandprizeOff.png)");
		$("#normal").css("background-image","url(img/normalprizeOff.png)");
		$("#third").css("background-image","url(img/thirdprizeOff.png)");
		$("#second").css("background-image","url(img/secondprizeOff.png)");
		$("#first").css("background-image","url(img/firstprizeOn.png)");
});
$("#grand").click(function(){
		$(this).addClass("start");
		$(this).siblings().removeClass("start");
		$("div.prize-number").html("");
		$("#grand").css("background-image","url(img/grandprizeOn.png)");
		$("#normal").css("background-image","url(img/normalprizeOff.png)");
		$("#third").css("background-image","url(img/thirdprizeOff.png)");
		$("#second").css("background-image","url(img/secondprizeOff.png)");
		$("#first").css("background-image","url(img/firstprizeOff.png)");
		//var i=0;
		//a5=setTimeout(function(){
		//	start();	
		//	i++;
		//})
});
$("#start").click(function(){
	$(this).attr("disabled",true);
	$("div.prize button").attr("disabled",true);
	if($("#grand").hasClass("start")){
		var n=parseInt($("#grand").attr())
		start();	
	}
	if($("#first").hasClass("start")){
		var i=0;
		a4=setTimeout(function(){
			start();	
			i++;
		})
		b4=setInterval(function(){
			if(i<=2){
				start()
			}
			if(i==2){
				$("div.prize button").attr("disabled",false);
			}
			i++;
		},8500)
	}
	if($("#second").hasClass("start")){
		var i=0;
		a3=setTimeout(function(){
			start();	
			i++;
		})
		b3=setInterval(function(){
			if(i<=9){	
				start()
			}
			i++;
		},8500)
	}
	if($("#third").hasClass("start")){
		var i=0;
		a2=setTimeout(function(){
			start();	
			i++;
		})
		b2=setInterval(function(){
			if(i<=24){
				start()
			}
			i++;
		},8500)
	}
	if($("#normal").hasClass("start")){
		var i=0,
		a1=setTimeout(function(){
			start();	
			i++
		})
		b1=setInterval(function(){
			if(i<=49){
				start()
			}
			i++;
		},8500)
	}
})
$("#again").click(function(){
	$("#start").attr("disabled",false)
	$("div.prize button").attr("disabled",false);
})
function start(){
	var q=0,b=0,s=0,g=0,number="";
	var timer1=setInterval(function(){
		q++;
		if(q == 4){
			clearInterval(timer1);
		}
		var n=parseInt(1+Math.random()*3);
		$("#thousand").text(n)
	},500)
	var timer2=setInterval(function(){
		b++;
		if(b == 8){
			clearInterval(timer2);
		}
		var n=parseInt(Math.random()*3);
		$("#hundred").text(n)
	},500)
	var timer3=setInterval(function(){
		s++;
		if(s == 12){
			clearInterval(timer3);
		}
		var n=parseInt(Math.random()*10);
		$("#ten").text(n)
	},500)
	var timer4=setInterval(function(){
		g++;
		if(g == 16) {
			clearInterval(timer4);
			number=$("#thousand").text()+$("#hundred").text()+$("#ten").text()+$("#digit").text();
			$("div.prize-number").append("<span class='normal'>"+number+"</span>");
		}
		if(g<16){
			
		var n=parseInt(Math.random()*10);
		$("#digit").text(n)
		}
	},500)
}